package per.turtle.system.service.impl;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import per.turtle.system.entity.SysNotice;
import per.turtle.system.mapper.SysNoticeMapper;
import per.turtle.system.service.ISysNoticeService;

import java.util.List;

/**
 * 公告 服务层实现
 *
 * @author turtle
 */
@Service
public class SysNoticeServiceImpl extends ServiceImpl<SysNoticeMapper, SysNotice> implements ISysNoticeService {

    @Override
    public int deleteNoticeByIds(List<Long> noticeIds) {
        return baseMapper.deleteBatchIds(noticeIds);
    }

    @Override
    public int insertNotice(SysNotice notice) {
        return baseMapper.insert(notice);
    }

    @Override
    public SysNotice selectNoticeById(Long noticeId) {
        return baseMapper.selectById(noticeId);
    }

    @Override
    public List<SysNotice> selectNoticeList(SysNotice notice) {
        QueryWrapper<SysNotice> wrapper = new QueryWrapper<>(notice);
        wrapper.getEntity().setNoticeTitle(null);
        wrapper.lambda().like(StrUtil.isNotBlank(notice.getNoticeTitle()), SysNotice::getNoticeTitle, notice.getNoticeTitle());
        return baseMapper.selectList(wrapper);
    }

    @Override
    public int updateNotice(SysNotice notice) {
        return baseMapper.updateById(notice);
    }

}
